﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using BPMS.Utility.Web;

namespace BPMS.Web.Extends.Modules
{
    public class RequestVerifyModule : IHttpModule
    {
        public void Dispose()
        {
        }

        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
        }
        void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpRequest request = application.Context.Request;
            HttpResponse response = application.Context.Response;
            string q = "<div style='position:fixed;top:0px;width:100%;height:100%;background-color:white;color:green;font-weight:bold;border-bottom:5px solid #999;'><br>您的提交带有不合法参数,谢谢合作!<br><br>了解更多请点击:<a href='http://webscan.360.cn'>360网站安全检测</a></div>";
            if (request.Cookies != null)
            {
                if (RequestDataVerify.BadCookieData())
                {
                    response.Write(q);
                    response.End();

                }


            }

            if (request.UrlReferrer != null)
            {
                if (RequestDataVerify.BadRefererRequest())
                {
                    response.Write(q);
                    response.End();
                }
            }

            if (request.RequestType.ToUpper() == "POST")
            {
                if (RequestDataVerify.BadPostRequest())
                {

                    response.Write(q);
                    response.End();
                }
            }

            if (request.RequestType.ToUpper() == "GET")
            {
                if (RequestDataVerify.BadGetRequest())
                {
                    response.Write(q);
                    response.End();
                }
            }

        }
    }
}
